package com.ghostbusters.fingertracker.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MapUtil <E> {

	public Map<E, Double> findBelowThreshold(Map<E, Double> map, double threshold) {
		Map<E, Double> doneMap = new HashMap<E, Double>();

		for ( E key : map.keySet()) {
			if( threshold > map.get(key)) {
				doneMap.put(key, map.get(key));
			}
		}
		
		return doneMap;	
	}
	
	// could be optimized by factoring in if index is before or after middle
	public List<E> splitFrom(List<E> list, int index) {
		List<E> doneList = new ArrayList<E>();
		
		for (int i = index; i < list.size(); i++) {
			doneList.add(list.get(i));
		}
		return doneList;
	}
	
	public Map<E, Double> findMin( Map<E, Double> eToDouble) {
		Map<E, Double> doneMap = new HashMap<E,Double>();
		E keyOfMin = null;
		Double min = null;
		
		for( E key : eToDouble.keySet()) {
			if( min == null) {
				keyOfMin = key;
				min = eToDouble.get(key);
			} else {
				if (eToDouble.get(key) < min) {
					keyOfMin = key;
					min = eToDouble.get(key);
				}
			}
			
		}
		doneMap.put(keyOfMin, min);
		
		return doneMap;
	}
}
